package com.iwhalecloud.bss.kite.cucc.spec.impl.query;

import com.iwhalecloud.bss.kite.common.constant.KeyConsts;
import com.iwhalecloud.bss.kite.cucc.client.api.goods.IGoodsService;
import com.iwhalecloud.bss.kite.cucc.spec.impl.transfer.GoodsInfoTransfer;
import com.iwhalecloud.bss.kite.dataservice.api.IQueryOfferRestrictService;
import com.iwhalecloud.bss.kite.dataservice.cache.OfferCache;
import com.iwhalecloud.bss.kite.dataservice.entity.spec.Offer;
import com.iwhalecloud.bss.kite.dataservice.entity.spec.OfferRestrict;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.Objects;

@Service
public class OfferRestrictQueryService implements IQueryOfferRestrictService {

	@Autowired
	private IGoodsService goodsService;

	@Override
	public List<OfferRestrict> listOfferServPrivCfgs(String objectType, String objectId) {
		return Collections.emptyList();
	}

	@Override
	public List<OfferRestrict> listOfferRestrictsByOfferId(String objectType, String objectId) {
		Offer offer = OfferCache.get(objectId);
		if (Objects.nonNull(offer) && KeyConsts.OFFER_TYPE_12.equals(offer.getOfferType())) {
			return Collections.emptyList();
		}
		Map good = goodsService.queryGoodsByOfferId(objectId);
        return GoodsInfoTransfer.convertOfferRestrict(good);
	}

	@Override
	public List<OfferRestrict> listOfferRestricts(String objectType, String objectId) {
        return Collections.emptyList();
	}

}
